<?php
/**
 * Created by PhpStorm.
 * User: 戎大富
 * Date: 2019/4/26
 * Time: 11:33
 */
namespace app\admin\controller;
use think\Db;
class Reli extends Base {
    public function index(){

//        $data = [
//            ['name'=> '北京', 'value'=> 200],
//            ['name'=> '天津', 'value'=> 212],
//            ['name'=> '河南', 'value'=> 212],
//            ['name'=> '安徽', 'value'=> 212],
//            ['name'=> '江苏', 'value'=> 214]
//        ];
        $dis = 0;
        $where = array();
        $where['s_lon'] = ['>',0];
        $where['s_sheng'] = ['>',0];
        $data = Db::table('up_shops')->alias('shop')
            ->join('up_area a','shop.s_sheng = a.district_id')
            ->where($where)
            ->group('s_sheng')
            ->field('district name,count(*) as value')
            ->select();
        if($data){
            $dis = 1;
            foreach ($data as $k=>$v){
                //1、先去掉 省 字
                $data[$k]['name'] = str_replace("省","",$v['name']);
                //2、再转化特殊区域
                if($v['name'] == '西藏自治区'){ $data[$k]['name'] = '西藏'; }
                if($v['name'] == '广西壮族自治区'){ $data[$k]['name'] = '广西'; }
                if($v['name'] == '内蒙古自治区'){ $data[$k]['name'] = '内蒙古'; }
                if($v['name'] == '宁夏回族自治区'){ $data[$k]['name'] = '宁夏'; }
                if($v['name'] == '新疆维吾尔自治区'){ $data[$k]['name'] = '新疆'; }
                if($v['name'] == '香港特别行政区'){ $data[$k]['name'] = '香港'; }
                if($v['name'] == '澳门特别行政区'){ $data[$k]['name'] = '澳门'; }
            }
        }
        $data = json_encode($data);
        $this->assign('data',$data);
        $this->assign('dis',$dis);
        return $this->fetch();
    }
    public function users(){

//        $data = [
//            ['name'=> '北京', 'value'=> 200],
//            ['name'=> '天津', 'value'=> 212],
//            ['name'=> '河南', 'value'=> 212],
//            ['name'=> '安徽', 'value'=> 212],
//            ['name'=> '江苏', 'value'=> 214]
//        ];
        $dis = 0;
        $where = array();
//        $where['user_lat'] = ['>',0];
        $where['user_province'] = ['>',0];
        $data = Db::table('up_u_user')->alias('shop')
            ->join('up_area a','shop.user_province = a.district_id')
            ->where($where)
            ->group('user_province')
            ->field('district name,count(*) as value')
            ->select();
        if($data){
            $dis = 1;
            foreach ($data as $k=>$v){
                //1、先去掉 省 字
                $data[$k]['name'] = str_replace("省","",$v['name']);
                //2、再转化特殊区域
                if($v['name'] == '西藏自治区'){ $data[$k]['name'] = '西藏'; }
                if($v['name'] == '广西壮族自治区'){ $data[$k]['name'] = '广西'; }
                if($v['name'] == '内蒙古自治区'){ $data[$k]['name'] = '内蒙古'; }
                if($v['name'] == '宁夏回族自治区'){ $data[$k]['name'] = '宁夏'; }
                if($v['name'] == '新疆维吾尔自治区'){ $data[$k]['name'] = '新疆'; }
                if($v['name'] == '香港特别行政区'){ $data[$k]['name'] = '香港'; }
                if($v['name'] == '澳门特别行政区'){ $data[$k]['name'] = '澳门'; }
            }
        }
        $data = json_encode($data);
        $this->assign('data',$data);
        $this->assign('dis',$dis);
        return $this->fetch();
    }
}